import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { dictItemCheck } from './dict.api';
import { rules } from '/@/utils/helper/validator';
import { h } from 'vue';
import { initDictOptions } from '/@/utils/dict';
import { render } from '/@/utils/common/renderUtils';
import { getSingersAllList } from './projectVote.api';

export const columns: BasicColumn[] = [
  {
    title: '投票项目编号',
    dataIndex: 'id',
  },
  {
    title: '投票名称',
    dataIndex: 'name',
  },
  {
    title: '投票状态',
    dataIndex: 'status',
    format: (v) => {
      return v == '0' ? '是' : '否';
    },
  },
  {
    title: '投票内容',
    dataIndex: 'content',
  },
  {
    title: '投票总数量',
    dataIndex: 'count',
    format: (v) => {
      return v || '0';
    },
  },
  {
    title: '投票类型',
    dataIndex: 'type',
    customRender: ({ text }) => {
      return render.renderDicts(text, 'votingType');
    },
  },
  {
    title: '是否发布',
    dataIndex: 'published',
    format: (v) => {
      return v == '0' ? '是' : '否';
    },
  },
  {
    title: '开始时间',
    dataIndex: 'startTime',
  },
  {
    title: '结束时间',
    dataIndex: 'endTime',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '投票名称',
    field: 'name',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: '投票状态',
    field: 'status',
    component: 'Select',
    componentProps: {
      options: [
        {
          label: '是',
          value: 0,
        },
        {
          label: '否',
          value: 1,
        },
      ],
    },
    colProps: { span: 6 },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: '投票名称',
    field: 'name',
    required: true,
    component: 'Input',
  },
  {
    label: '歌手',
    field: 'singerIds',
    required: true,
    component: 'ApiSelect',
    componentProps: {
      api: getSingersAllList,
      labelField: 'name',
      valueField: 'id',
      mode: 'multiple',
    },
  },
  {
    label: '投票类型',
    field: 'type',
    required: true,
    component: 'JSelectMultiple',
    componentProps: {
      dictCode: 'votingType',
      stringToNumber: true,
    },
  },
  {
    label: '投票状态',
    field: 'status',
    component: 'RadioGroup',
    componentProps: {
      options: [
        {
          label: '开启',
          value: 0,
        },
        {
          label: '关闭',
          value: 1,
        },
      ],
    },
  },
  {
    label: '投票内容',
    field: 'content',
    component: 'Input',
  },
  {
    label: '是否发布',
    field: 'published',
    component: 'RadioGroup',
    componentProps: {
      options: [
        {
          label: '是',
          value: 0,
        },
        {
          label: '否',
          value: 1,
        },
      ],
    },
  },
  {
    label: '发布链接',
    field: 'address',
    component: 'Input',
    componentProps: ({ formModel, formActionType }) => {
      formModel.address = 'http://localhost:3001/login/page?projectId=' + formModel.id; //  reset city value
      return {};
    },
    ifShow: ({ values }) => values.published == 0,
  },
  {
    label: '开始时间',
    field: 'startTime',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD HH:mm:ss',
      showTime: true,
    },
  },
  {
    label: '结束时间',
    field: 'endTime',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD HH:mm:ss',
      showTime: true,
    },
  },
];
